package com.flute.haflute.jobbox.communication.messages;

import com.flute.haflute.jobbox.base.CloudJobConf;
import com.flute.haflute.jobbox.common.CloudConstants;

/**
 * 非Mapreduce任务的内部请求消息， 封装用于主节点和子节点任务通信
 */
public class CloudJobReqMessage implements RequestMessage {
	private static final long serialVersionUID = -1030319026065862836L;
	public static final String type = "CloudJobReqMessage";

	/** 任务配置 */
	private CloudJobConf jobConf;
	/** 当前任务的标识符 */
	private String sourceId = CloudConstants.JOB_SOURCE_INPUT_NONE;
	/** 当前任务的消息管理器 */
	private String messagerId = CloudConstants.JOB_REQ_MESSAGER_NONE;

	@Override
	public void setContent(Object obj) {
		if (obj instanceof CloudJobConf) {
			jobConf = (CloudJobConf) obj;
		}
	}

	@Override
	public Object getContent() {
		return jobConf;
	}

	@Override
	public CloudJobConf getJobConf() {
		return jobConf;
	}

	@Override
	public String getSourceId() {
		return sourceId;
	}

	public void setSourceId(String sourceId) {
		this.sourceId = sourceId;
	}

	@Override
	public String getMessagerId() {
		return messagerId;
	}

	public void setMessagerId(String messagerId) {
		this.messagerId = messagerId;
	}

	@Override
	public String getType() {
		return type;
	}

	/*
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((jobConf == null) ? 0 : jobConf.hashCode());
		result = prime * result
				+ ((messagerId == null) ? 0 : messagerId.hashCode());
		result = prime * result
				+ ((sourceId == null) ? 0 : sourceId.hashCode());
		return result;
	}

	/*
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CloudJobReqMessage other = (CloudJobReqMessage) obj;
		if (jobConf == null) {
			if (other.jobConf != null)
				return false;
		} else if (!jobConf.getJobId().equals(other.jobConf.getJobId()))
			return false;
		return true;
	}

}
